{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Represent your vectors as a matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the culmination of chapter 4, I stated a big idea: any linear transformation in 3D can be specified by just three vectors or nine numbers total. By correctly selecting these nine numbers, we can achieve rotation by any angle about any axis, reflection across any plane, projection onto any plane, scaling by any factor in any direction, or any other 3D linear transformation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In mathematics, the standard basis (also called natural basis) of a coordinate vector space is the set of vectors whose coordinates are all zero, except one that equals 1. For example, in the case of the Euclidean plane formed by the pairs (x, y) of real numbers, the standard basis is formed by the vectors\n",
    "\n",
    "$$\n",
    "{\\displaystyle \\mathbf {e} _{x}=(1,0),\\quad \\mathbf {e} _{y}=(0,1).}\n",
    "$$\n",
    "\n",
    "Similarly, the standard basis for the three-dimensional space is formed by vectors\n",
    "\n",
    "$$\n",
    "{\\displaystyle \\mathbf {e} _{x}=(1,0,0),\\quad \\mathbf {e} _{y}=(0,1,0),\\quad \\mathbf {e} _{z}=(0,0,1).}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The standard basis for three dimensions can be written as three column vectors like this:\n",
    "\n",
    "$$\n",
    "e_x = \\begin{pmatrix}\n",
    "1 \\\\\n",
    "0 \\\\\n",
    "0 \\\\\n",
    "\\end{pmatrix}\n",
    ",\n",
    "\\quad\n",
    "e_y = \\begin{pmatrix}\n",
    "0 \\\\\n",
    "1 \\\\\n",
    "0 \\\\\n",
    "\\end{pmatrix}\n",
    ",\n",
    "\\quad\n",
    "e_z = \\begin{pmatrix}\n",
    "0 \\\\\n",
    "0 \\\\\n",
    "1 \\\\\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If we have a 3D linear transformation `A` that does no transformation, `A` would be a 3-by-3 grid consisting of these vectors squashed together side by side:\n",
    "\n",
    "$$\n",
    "A = \\begin{pmatrix}\n",
    "1 & 0 & 0 \\\\\n",
    "0 & 1 & 0 \\\\\n",
    "0 & 0 & 1\n",
    "\\end{pmatrix}\n",
    "$$\n",
    "\n",
    "> The way to get a matrix from a linear transformation is to find the vectors it produces from all of the standard basis vectors and combine the results side by side."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Get columns from your matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(0, 0, 1), (2, 1, 0), (1, 0, -1)]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B = [\n",
    "    [0,2,1], \n",
    "    [0,1,0], \n",
    "    [1,0,-1]\n",
    "]\n",
    "\n",
    "list(zip(*B))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Matrix multiplication\n",
    "\n",
    "It's a calculation process that hard to descript with pure languages.\n",
    "\n",
    "But here's a tutorial that may help you undertand the process:\n",
    "\n",
    "https://www.khanacademy.org/math/precalculus/x9e81a4f98389efdf:matrices/x9e81a4f98389efdf:multiplying-matrices-by-matrices/v/matrix-multiplication-intro\n",
    "\n",
    "\n",
    "![image.png](images/matrix-multiplication.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Rules for matrix multiplication\n",
    "\n",
    "Set a, b as two matrix, their shape must be `m*k` and `k*n`, where `k==k`.\n",
    "\n",
    "```\n",
    "[ 1 1 1\n",
    "  2 2 2 ]\n",
    "\n",
    "m == 2, k == 3\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
